<?php

class Ms_Form_Nologincomment extends Zend_Form
{
    private $_captchaUrl = null;

    public function init()
    {
//        $nologincomment = $this->createElement('textarea','comment');
//        $nologincomment->setLabel('内容：');
//        $this->addElement($nologincomment);
//
//        // 提交按钮
//        $submit = $this->createElement('submit', '提交');
//        $this->addElement($submit);
//
//        /**
//         +----------------------------------------------------------
//         * 覆写装饰器
//         +----------------------------------------------------------
//        */
//         $this->setElementDecorators(array(
//                'ViewHelper',
//                'Errors',
//                 array('decorator' => array('tr' => 'HtmlTag'), 'options' => array('tag' => 'tr')),
//                array('decorator' => array('td' => 'HtmlTag'), 'options' => array('tag' => 'td'))
//           ));
    
        $this->setMethod('post');
        // 主题标题
        $name = $this->createElement('text', 'name');
        $name->setLabel('名称：');
        $name->setRequired(TRUE);
        $name->addValidator('stringLength', false, array(2, 16));
        $name->addErrorMessage('名称应有2-16个汉字！');
        $this->addElement($name);
    
        // 主题内容
        $email = $this->createElement('text', 'email');
        $email->setLabel('邮箱：');
        $email->setRequired(TRUE);
        $email->addValidator('emailAddress');
        $email->addErrorMessage('请输入正确的邮箱！');
        $this->addElement($email);
    
        // 回复
        $comment = $this->createElement('textarea', 'comment');
        $comment->setLabel('回复：');
        $comment->setRequired(TRUE);
        $comment->addValidator('stringLength', false, array(10, 200));
        $comment->addErrorMessage('回复应有10-200个汉字。');
        $this->addElement($comment);
    
//        // 验证码
//        $captchaImgView = $this->createElement('image', 'captcha_img');
//        $captchaImgView->setAttrib('src', $captchaUrl);
//        $captchaImgView = new Zend_Form_Element_Image('image','captcha');
//        $captchaImgView->setImageValue($captchaUrl);
//        $captchaImgView->setAttrib('src', $captchaUrl);
//        $this->addElement($captchaImgView);
    
        // 验证码
        $captchaCode = $this->createElement('text', 'captcha_code');
        $captchaCode->setLabel('验证码：');
        $captchaCode->setAttrib('onclick',"showcaptcha(this)");
        $captchaCode->setRequired(TRUE);
        $captchaCode->addValidator('stringLength', false, array(5, 5));
        $captchaCode->addErrorMessage('请输入正确的验证码！');
        $this->addElement($captchaCode);
    
    
        // 提交按钮
        $submit = $this->createElement('submit', '提交');
        $this->addElement($submit);
    
        /**
        +----------------------------------------------------------
         * 覆写装饰器
        +----------------------------------------------------------
         */
    
        $this->setElementDecorators(array(
            'ViewHelper',
            'Errors',
            array('decorator' => array('td' => 'HtmlTag'), 'options' => array('tag' => 'td')),
            array('Label', array('tag' => 'td')),
            array('decorator' => array('tr' => 'HtmlTag'), 'options' => array('tag' => 'tr')),
        ));
    
        $submit->setDecorators(array(
            array(
                'decorator' => 'ViewHelper',
                'options' => array('helper' => 'formSubmit')),
            array(
                'decorator' => array('td' => 'HtmlTag'),
                'options' => array('tag' => 'td', 'colspan' => 2)),
            array(
                'decorator' => array('tr' => 'HtmlTag'),
                'options' => array('tag' => 'tr')),
        ));
    
        $this->addDecorator('FormElements')
             ->addDecorator('HtmlTag', array('tag' => 'table'))
             ->addDecorator('Form');
    }
}